        var cstore = new Ext.data.JsonStore({
			url: '/weihe/get_client',
			root: 'datas',
			fields : ['id','company','address','contact',
			          'email','linkman'],
			listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_client',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
		
		  var clientSLStore = new Ext.data.JsonStore({
			url: '/weihe/getList_shoppingList',
			root: 'datas',
			fields : [{
			        	   name:'osListId',mapping:'id'
			          },{
			        	   name:'osCode',mapping:'code' 
			          },{
			        	   name:'osListNum',mapping:'listNum' 
			          },{
        				   name:'osState',mapping:'state'
        			  },{
        				   name:'osPayment',mapping:'payment'
        			  },{
        				   name:'osDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'osType',mapping:'type'
        			  },{
        				   name:'osTotal',mapping:'total'
        			  },{
        				   name:'osClerk',mapping:'clerk'
        			  }]

		});
		
		var ilStore = new Ext.data.JsonStore({
			url: '/weihe/getList_invoiceList',
			root: 'datas',
			fields : [{
			        	   name:'invoiceListId',mapping:'id'
			          },{
			        	   name:'invoiceCompany',mapping:'company' 
			          },{
        				   name:'invoiceAddress',mapping:'address'
        			  },{
        				   name:'invoiceEmail',mapping:'email'
        			  },{
        				   name:'invoiceLinkman',mapping:'linkman'
        			  },{
        				   name:'invoiceContact',mapping:'contact'
        			  },{
        				   name:'invoicePayment',mapping:'payment'
        			  },{
        				   name:'invoiceDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'invoiceInvoiceNum',mapping:'invoiceNum'
        			  },{
        				   name:'invoiceTotal',mapping:'total'
        			  }]
		});
		
		   var cargoStore = new Ext.data.JsonStore({
			url: '/weihe/getSLCargo_shoppingList',
			root: 'datas',
			fields : [{
			        	   name:'shopId',mapping:'id'
			          },{
			        	   name:'shopAmount',mapping:'amount' 
			          },{
        				   name:'shopPrice',mapping:'price'
        			  },{
        				   name:'shopRemark',mapping:'remark'
        			  },{
        				   name:'shopSum',mapping:'sum'
        			  },{
        				   name:'shopState',mapping:'state'
        			  },{
        				   name:'shopOrigin',mapping:'cargo', convert:function(v){ 
														return v ? v.origin : undefined;}
        			  },{
						   name:'shopCode',mapping:'cargo', convert:function(v){ 
														return v ? v.code : undefined;}
			          },{
			        	   name:'shopName',mapping:'cargo', convert:function(v){ 
														return v ? v.name : undefined;}
			          },{
			        	   name:'shopSpecs',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.specs : undefined;}
			          },{
			        	   name:'shopUnit',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.unit : undefined;}
			          }]

		});
    
        
        

renders = function(){
  return{
  	
  	ilWin : function(){
  	  var ilWin = new Ext.Window({
        title:'订单表',
        layout: 'fit',
        width:600,    
        height:400,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[renders.listGrid()] 
        
    });  
  		return ilWin;
  	},
  	
  slWin : function(){
  	  var slWin = new Ext.Window({
        title:'采购单表',
        layout: 'fit',
        width:600,    
        height:400,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[renders.slGrid()] 
        
    });  
  		return slWin;
  	},
  	
  	  cargoWin : function(){
  	  var cargoWin = new Ext.Window({
        title:'采购货物表',
        layout: 'fit',
        width:600,    
        height:400,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[renders.cargoGrid()] 
        
    });  
  		return cargoWin;
  	},
  	
  	slGrid : function(){
	  
	var pageToolBar = new Ext.PagingToolbar({
		pageSize : 8,
		store : clientSLStore,
		displayInfo : true,
		displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
	    emptyMsg : "没有记录显示!",
	    firstText : '首页',
	    prevText : '上一页',
	    nextText : '下一页',
	    lastText : '尾页',
	    beforePageText : '第',
	    afterPageText : '页,共{0}页'
	});


	var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
	
	   
   var slGrid = new Ext.grid.GridPanel({
	   title: '采购单信息表',
	   region : 'center',
	   minColumnWidth : 35,
	   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
	   store : clientSLStore,
	   columns: [
	             {header : '订单号', dataIndex : 'osCode'},
	             {header : '采购单号', dataIndex : 'osListNum'},
	             {header : '日期', dataIndex : 'osDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
	             {header : '类型', dataIndex : 'osType', menuDisabled : true},
	             {header : '状态', dataIndex : 'osState', menuDisabled : true},
	             {header : '支付方式', dataIndex : 'osPayment', menuDisabled : true},
	             {header : '总价', dataIndex : 'osTotal', menuDisabled : true},
	             {header : '业务员', dataIndex : 'osClerk', menuDisabled : true}
	             ],
   sm : rowSelectionModel,
    listeners :{ 
			     'rowdblclick':function(grid, rowIndex, event) {
			  		 var record = grid.getStore().getAt(rowIndex);
			   			renders.cargoWin().show();
			   			cargoStore.baseParams = {'shoppingList.id' : record.id};
						cargoStore.load({params : {start : 0, limit : 8}});
			  
		  	 }
	   },
	  bbar : pageToolBar
});
	return slGrid;
},
  	
  	listGrid : function(){
	  
		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 8,
			store : ilStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
	   var listGrid = new Ext.grid.GridPanel({
		   title : '订单信息表',
		   minColumnWidth : 35,
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : ilStore,
		   columns: [
		             {header : '订单号', dataIndex : 'invoiceInvoiceNum', menuDisabled : true},
		             {header : '订单日期', dataIndex : 'invoiceDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
		             {header : '支付方式', dataIndex : 'invoicePayment', menuDisabled : true},
		             {header : '合计', dataIndex : 'invoiceTotal', menuDisabled : true}
		             ],
         sm : rowSelectionModel,
         listeners :{ 
			     'rowdblclick':function(grid, rowIndex, event) {
			  		 var record = grid.getStore().getAt(rowIndex);
			   			renders.slWin().show();
			   			clientSLStore.baseParams = {'id' : record.id};
						clientSLStore.load({params : {start : 0, limit : 8}});
			  
		  	 }
		   },
		  bbar : pageToolBar
});
		return listGrid;
	},
	
	cargoGrid : function(){
        			 


        			var pageToolBar = new Ext.PagingToolbar({
        				pageSize : 8,
        				store : cargoStore,
        				displayInfo : true,
        				displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
        			    emptyMsg : "没有记录显示!",
        			    firstText : '首页',
        			    prevText : '上一页',
        			    nextText : '下一页',
        			    lastText : '尾页',
        			    beforePageText : '第',
        			    afterPageText : '页,共{0}页'
        			   


        			});


        			var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
        			
        			   
        		   var cargoGrid = new Ext.grid.GridPanel({
        			   title : '采购货物信息表',
        			   minColumnWidth : 50,
        			   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
        			   store : cargoStore,
        			   columns: [
        			             {header : '产品编号', dataIndex : 'shopCode', menuDisabled : true},
        			             {header : '产品名称', dataIndex : 'shopName'},
        			             {header : '规格型号', dataIndex : 'shopSpecs', menuDisabled : true},
        			             {header : '单位', dataIndex : 'shopUnit', menuDisabled : true},
        			             {header : '单价', dataIndex : 'shopPrice',sortable : true},
        			             {header : '数量', dataIndex : 'shopAmount', menuDisabled : true},
        			             {header : '金额', dataIndex : 'shopSum', menuDisabled : true},
        			             {header : '状态', dataIndex : 'shopState', menuDisabled : true,renderer:function(value){
		           																						if(value == '未完成'){
		           																							return "<span style='color:red;font-weight:bold;'>未完成</span>";
		           																						}else{
		           																							return "<span style='color:green;font-weight:bold;'>已完成</span>";
		           																						}
		             }},
        			             {header : '备注', dataIndex : 'shopRemark', menuDisabled : true}
        	        ],
        	           sm : rowSelectionModel,
        			  viewConfig : {
        			     forceFit : false
        			  },
        			  bbar : pageToolBar
        	});
        			return cargoGrid;
        		},
     
    grid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 15,
			store : cstore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		    InfoFormPanel = Ext.extend(Ext.form.FormPanel , {
			
			constructor:function(){
				
				 InfoFormPanel.superclass.constructor.call(this , {
						labelWidth:55,
						defaultType:"textfield",
						defaults:{anchor:"98%"},
						baseCls:"x-plain",
						items:[{
							fieldLabel:"项目",
							name:"client.project"
						},{
							 fieldLabel:"客户",
							 name:"client.name"
						},{
							fieldLabel : '付款日期',
							name : 'client.paymentDate',
							xtype : 'datefield',
							format : 'Y-m-d'
						},{
							fieldLabel : '发送港口',
							name : 'client.port'
						},{
							fieldLabel : '发送日期',
							name : 'client.sentDate',
							xtype : 'datefield',
							format : 'Y-m-d'
						}]
				}) ;
			},
			getValues:function(){
				
				if(this.getForm().isValid())
				
					return new Ext.data.Record(this.getForm().getValues()) ;
					
				else
				
					throw Error("表单验证没有通过") ;
			},
			setValues:function(_r){
				
				this.getForm().loadRecord(_r) ;
			},
			reset:function(){
				
				this.getForm().reset() ;
			}
		}) ;

		/***************************************************************************************************************************/

		InsertInfoWindow = Ext.extend(Ext.Window , {
			
			form:new  InfoFormPanel(),
			
			constructor:function(){
				
				InsertInfoWindow.superclass.constructor.call(this , {
						
						plain:true,
						
						width:300,
						
						modal:true,
						
						items:this.form,
						
						closeAction:"hide",
						
						buttons:[{
							text:"确 定",
							handler:this.onSubmitClick,
							scope:this
						},{
							text:"取 消",
							handler:this.onCancelClick,
							scope:this
						}]
				}) ;
				
				this.addEvents("submit") ;
			},
			
			close:function(){
				
				this.form.reset() ;
				
				this.hide() ;
			},
			
			onSubmitClick:function(){
				 var x = this.form.getValues();
				 Ext.getCmp("cgrid").getStore().baseParams = {'flag': true,'client.name':x.get("client.name"),
					 													  'client.project':x.get("client.project"),
					 													  'client.paymentDate':x.get("client.paymentDate"),
					 													  'client.port':x.get("client.port"),
					 													  'client.sentDate':x.get("client.sentDate")
					 
				 
				 };
				 Ext.getCmp("cgrid").getStore().load({params : {start : 0, limit : 15}});
				this.close() ;
			},
			onCancelClick:function(){
				this.form.reset();
				this.close() ;
			}
			
		}) ;

	   var insertWin = new InsertInfoWindow();
	   var grid = new Ext.grid.GridPanel({
		   id:'cgrid',
		   title : '客户信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   tbar:[{
			  	text:"输入查询条件",
				handler:function(){
					
					insertWin.show() ;
				},
				
				scope:this
		},"-",{
		  	text:"查看全部",
			handler:function(){
			Ext.getCmp("cgrid").getStore().baseParams = null;
			 Ext.getCmp("cgrid").getStore().load({params : {start : 0, limit : 15}});
			},
			
			scope:this
	}],

		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : cstore,
		   columns: [
		             {header : '客户名称', dataIndex : 'company', menuDisabled : true},
		             {header : '地址', dataIndex : 'address'},
		             {header : 'EMAIl', dataIndex : 'email', menuDisabled : true},
		             {header : '联系人', dataIndex : 'linkman', menuDisabled : true},
		             {header : '联系方式', dataIndex : 'contact', menuDisabled : true}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowdblclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   		renders.ilWin().show();
			   		ilStore.baseParams = {'query' : record.get('company')};
					ilStore.load({params : {start : 0, limit : 8}});
			  
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	}
  }
}();








